package com.lili.order.service.impl.aftersale;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lili.model.order.entity.PageMap;
import com.lili.model.order.entity.aftersale.AfterSaleReason;
import com.lili.order.mapper.aftersale.AfterSaleReasonMapper;
import com.lili.order.service.aftersale.AfterSaleReasonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Map;
@Service
public class AfterSaleReasonServiceImpl implements AfterSaleReasonService {
    @Autowired
    AfterSaleReasonMapper afterSaleReasonMapper;
    @Override
    public int save(AfterSaleReason afterSaleReason) {
        return afterSaleReasonMapper.insert(afterSaleReason);
    }

    @Override
    public int delete(Serializable id) {
        return afterSaleReasonMapper.myDeleteById(id);
    }

    @Override
    public int update(AfterSaleReason afterSaleReason) {
        QueryWrapper<AfterSaleReason> wrapper=new QueryWrapper<>();
        wrapper.eq("id",afterSaleReason.getId());
        return afterSaleReasonMapper.update(afterSaleReason,wrapper);
    }

    @Override
    public Page<AfterSaleReason> queryByPage(Map map) {
        QueryWrapper<AfterSaleReason> wrapper=new QueryWrapper<>();
        PageMap pageMap=new PageMap(map);
        wrapper.eq("delete_flag",0);
        if(map.containsKey("serviceType")){
            wrapper.like("service_type",map.get("serviceType"));
        }
        if(map.containsKey("storeId")){
            wrapper.like("store_id",map.get("storeId"));
        }
        Page<AfterSaleReason> page = new Page<>(pageMap.getPage(), pageMap.getPageSize());
        afterSaleReasonMapper.selectPage(page,wrapper);

        return page;
    }


}